package boogui.member;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import boogui.member.db.BooguiDAO;
import boogui.member.db.BooguiDBVO;
import boogui.member.db.IBooguiDAO;

/*
 * 아이디/비밀번호 찾기
 */

public class MemberFindDAO implements IMemberFindDAO {
	IBooguiDAO bdao = null;
	BooguiDBVO bdbvo = null;

	public MemberFindDAO() {
		bdao = new BooguiDAO();
		bdbvo = new BooguiDBVO();
	}

	// id찾기
	@Override
	public String findId(String name, String email) {
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		String result = "";

		try {
			conn = bdao.openDatabase();
			pstmt = conn.prepareStatement(bdbvo.getFindIdSQL());
			pstmt.setString(1, name);
			pstmt.setString(2, email);
			rs = pstmt.executeQuery();
			if (rs.next()) {
				result = rs.getString("memid");
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			bdao.closeDatabase(conn, pstmt, rs);
		}
		return result;
	}

	// 비밀번호 찾기
	@Override
	public String findPwd(String id, String name, String email) {
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		String result = "";

		try {
			conn = bdao.openDatabase();
			pstmt = conn.prepareStatement(bdbvo.getFindPwdSQL());
			pstmt.setString(1, id);
			pstmt.setString(2, name);
			pstmt.setString(3, email);
			rs = pstmt.executeQuery();
			if (rs.next()) {
				result = rs.getString("mempwd");
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			bdao.closeDatabase(conn, pstmt, rs);
		}
		return result;
	}
}
